package com.controller.selling
{	
	import com.events.selling.SBEvent;
	import com.model.valueObjects.VoSalesBrochure;
	import com.service.SalesBrochure;
	
	import mx.collections.ArrayCollection;
	import mx.collections.Sort;
	import mx.collections.SortField;
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class SBController extends AbstractController
	{
		
		[Inject]
		public var salesBrochureDetails:SalesBrochure;
		
		public function SBController()
		{
			super();
		}
		
		[EventHandler(event="SBEvent.GET_ALL")]
		public function getAll():void{
		sh.executeServiceCall(salesBrochureDetails.slowMovingStock(),getAllResult, handleFault );
		}
		
		private function getAllResult(event:ResultEvent):void
		{
			model.slowMovingStockList=event.result as ArrayCollection;
			
			//Sorting By Stock - Sold			
			var dataSortField:SortField = new SortField();
			dataSortField.name = "pro_stock";
			dataSortField.numeric = true;
			var numericDataSort:Sort= new Sort();
			numericDataSort.fields = [dataSortField];
			model.slowMovingStockList.sort = numericDataSort;
			model.slowMovingStockList.refresh();
			
			CursorManager.removeBusyCursor();
			model.busyCurrsorOn=true;
		}
		
		private function handleFault(event:FaultEvent):void
		{
			Alert.show( event.fault.faultDetail, "Error" );
		}
	}
}